package com.demospringboot.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    //直接返回成功结果
    public static <T> Result<T> success(){
        return new Result<>(200,"success",null);
    }
    //返回成功结果和数据集
    public static <T> Result<T> success(T data){
        return new Result<>(200,"success",data);
    }
    //返回提示信息和数据集
    public static <T> Result<T> success(T data,String msg){
        return new Result<>(200,msg,data);
    }
    //返回提示信息
    public static <T> Result<T> success(String msg){
        return new Result<>(200,msg,null);
    }

    //返回失败结果
    public static <T> Result<T> fail(){
        return new Result<>(400,"fail",null);
    }
    public static <T> Result<T> fail(Integer code){
        return new Result<>(code,"fail",null);
    }
    public static <T> Result<T> fail(Integer code,String msg){
        return new Result<>(code,msg,null);
    }
    public static <T> Result<T> fail(String msg){
        return new Result<>(400,msg,null);
    }

}
